<template>
  <div class="coursesNav">
    <div class="container">
      <!-- <router-link
        :to="{ name: item.name }"
        v-for="(item, index) in routeList"
        :key="index"
      > -->
        <div class="flexBox" v-for="(item, index) in routeList" :key="index" @click="handleChangePage(item)">
          <!-- <div>
            <img :src="require('@/assets/images/carouselRight.png')" alt="" />
          </div> -->
          <div class="title" :class="{ isActive: currPage == item.routePath }" v-if="getTeacherRole || (!getTeacherRole && (index != 1 && index != 2)) ">
            {{ item.name }}({{courseCount[item.routePath]}})
          </div>
        </div>
      <!-- </router-link> -->
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';

export default {
  data() {
    return {
      routeList: [
        {name: "课程库", routePath:"courseStore"}, {name: "正在开课", routePath:"openedCourses"}, {name: "已取消", routePath: "deleteCourses"}
      ],
      currPage: "courseStore"
    };
  },
  props: {
    courseCount: Object
  },
  computed:{
    ...mapState({
      userInfo: (state) => state.user.userInfo,
    }),
    getTeacherRole() {
      return this.userInfo?.authNum ? this.userInfo.authNum.indexOf(2) !== -1 : false
    }
  },
  created() {
    // this.routeList = this.$store.state.permission.routes
    //   .filter((item) => item.name === "courseStore")[0]
    //   ?.children.filter((item) => item.name !== "store_browseDetail");
  },
  methods: {
    handleChangePage(item) {
      this.currPage =  item.routePath
      this.$emit("change", item)
    }
  }
};
</script>

<style lang="stylus">
.coursesNav {
  height: 70px;
  background-color: #ffffff;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.06);

  .container {
    padding: 0 0 10px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    max-width: 1200px;
    height: 100%;

    .flexBox {
      cursor pointer
      margin-right: 205px;
      display: flex;
      align-items: center;
      height: 27px;

      .title {
        margin-left: 5px;
        font-family: PMingLiU-ExtB;
        font-size: 16px;
        color: #003262;
      }

      .isActive {
        position: relative;
        font-weight: bold;
      }

      .isActive::after {
        position: absolute;
        content: '';
        left: 50%;
        right: 50%;
        bottom: -5px;
        width: 19px;
        height: 2px;
        background: #003262;
        transform: translate(-50%, 0);
      }
    }

    a:last-child {
      .flexBox {
        margin-right: 0;
      }
    }

    @media only screen and (max-width: 767px) {
      .flexBox {
        margin-right: 60px;
      }
    }

    .rightBox {
      margin-left: 205px;
    }
  }
}
</style>